package com.neusoft.data.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.neusoft.data.domain.SerServiceEvaluation;
import com.ruoyi.common.core.domain.model.LoginUser;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.neusoft.data.domain.SerScore;
import com.neusoft.data.service.ISerScoreService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 课程成绩Controller
 * 
 * @author slh
 * @date 2023-12-31
 */
@RestController
@RequestMapping("/courseSelect/score")
public class SerScoreController extends BaseController
{
    @Autowired
    private ISerScoreService serScoreService;

    /**
     * 查询课程成绩列表
     */
    @PreAuthorize("@ss.hasPermi('courseSelect:score:list')")
    @GetMapping("/list")
    public TableDataInfo list(SerScore serScore)
    {
        startPage();
        List<SerScore> list = serScoreService.selectSerScoreList(serScore);
        return getDataTable(list);
    }

    /**
     * 导出课程成绩列表
     */
    @PreAuthorize("@ss.hasPermi('courseSelect:score:export')")
    @Log(title = "课程成绩", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SerScore serScore)
    {
        List<SerScore> list = serScoreService.selectSerScoreList(serScore);
        ExcelUtil<SerScore> util = new ExcelUtil<SerScore>(SerScore.class);
        util.exportExcel(response, list, "课程成绩数据");
    }

    /**
     * 获取课程成绩详细信息
     */
    @PreAuthorize("@ss.hasPermi('courseSelect:score:query')")
    @GetMapping(value = "/{scoreId}")
    public AjaxResult getInfo(@PathVariable("scoreId") Long scoreId)
    {
        return success(serScoreService.selectSerScoreByScoreId(scoreId));
    }

    /**
     * 新增课程成绩
     */
    @PreAuthorize("@ss.hasPermi('courseSelect:score:add')")
    @Log(title = "课程成绩", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SerScore serScore)
    {
        return toAjax(serScoreService.insertSerScore(serScore));
    }

    /**
     * 修改课程成绩
     */
    @PreAuthorize("@ss.hasPermi('courseSelect:score:edit')")
    @Log(title = "课程成绩", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SerScore serScore)
    {
        return toAjax(serScoreService.updateSerScore(serScore));
    }

    /**
     * 删除课程成绩
     */
    @PreAuthorize("@ss.hasPermi('courseSelect:score:remove')")
    @Log(title = "课程成绩", businessType = BusinessType.DELETE)
	@DeleteMapping("/{scoreIds}")
    public AjaxResult remove(@PathVariable Long[] scoreIds)
    {
        return toAjax(serScoreService.deleteSerScoreByScoreIds(scoreIds));
    }

    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<SerScore> util = new ExcelUtil<SerScore>(SerScore.class);
        List<SerScore> userList = util.importExcel(file.getInputStream());
        LoginUser loginUser = getLoginUser();
        String operName = loginUser.getUsername();
        String message = serScoreService.importUser(userList, updateSupport, operName);
        return AjaxResult.success(message);
    }

    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) {
        ExcelUtil<SerScore> util = new ExcelUtil<>(SerScore.class);
        util.importTemplateExcel(response, "聊天数据");
    }

    @GetMapping("/years")
    public AjaxResult years() {
        return AjaxResult.success(serScoreService.getYears());
    }

    @GetMapping("/names")
    public AjaxResult names() {
        return AjaxResult.success(serScoreService.getNames());
    }
}
